'use strict';

// const mongoose = require('mongoose')

exports.drop = function () {
  // const Models = [mongoose.model('User')]
  // mongoose.set('debug', true)
  // const mNames = mongoose.modelNames()
  const db = require('../../../server/config/db').main;
  // const mNames = ['User', 'File']
  const mNames = db.modelNames();
  // console.log(db.modelNames())
  // yield getColletionNames(mongoose)
  // const cNames = Object.keys(Models[0].collection)
  console.info('will clear db collection : ', mNames);
  const Models = mNames.map((m) => db.model(m));
  return Models.map(dropCollection);
};

function dropCollection (Model) {
  return new Promise(function (resolve, reject) {
    Model.collection.remove(function (err) {
      if (err) {
        return reject(err);
      }
      return resolve();
    });
  });
}
/**
function getColletionNames (mongoose) {
  return new Promise((resolve, reject) => {
    mongoose.connection.db.collectionNames((err, collections) => {
      if (err) {
        console.error('err:', err)
        return reject(err)
      }
      console.log('collections', collections)
      resolve(collections)
    })
  })
}
**/
